package com.qf.springboot2203.controller;

import com.qf.springboot2203.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping
@RestController
@Slf4j
public class TestController {

    @GetMapping("/test")
    public String test(){

        return "66";
    }
    @RequestMapping("/user/login")
    public String test(User user,boolean rememberMe){

        Subject subject = SecurityUtils.getSubject();

        UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(user.getUsername(),user.getPassword());

        subject.login(usernamePasswordToken);

        return "ok";
    }

    @RequiresRoles("admin")
    @RequestMapping("/role")
    public String role(){

        return "ok";
    }

}
